package com.tianqu.tms.entity;

import java.sql.Timestamp;

import com.tianqu.tms.core.base.TmsEntity;
import com.tianqu.tms.core.exception.TmsDaoException;
import com.tianqu.tms.core.exception.TmsException;
import com.tianqu.tms.dao.CheckInfoDao;
import com.tianqu.tms.dao.TmsDao;
import com.tianqu.tms.dto.CheckInfoDto;

public class CheckInfo extends TmsEntity {
	private static final long serialVersionUID = -8961541240122668598L;
	// Id
	private String id;
	private String serial;
	// 车牌号码
	private String licensePlate;
	// VIN码
	private String vin;
	// 号牌种类
	private int cardType;
	// 车主类型
	private int ownerType;
	// 车主姓名
	private String carOwner;
	// 车主身份证号
	private String carOwnerIdCardNo;
	// 组织机构代码证号
	private String ownerOrgNo;
	// 车主地址
	private String ownerAddress;
	// 受理人
	private int insertUserId;
	// 受理时间
	private Timestamp insertTime;
	// 更新人
	private int updateUserId;
	// 更新时间
	private Timestamp updateTime;

	public static CheckInfo getInstance() {
		CheckInfo check = new CheckInfo();
		check.setExisting(false);
		return check;
	}

	/**
	 * 插入车辆信息
	 * 
	 * @throws TmsDaoException
	 */
	public void saveCheckcarInfo(CheckInfo entity) throws TmsDaoException {
		CheckInfoDao dao = (CheckInfoDao) TmsDao
				.getInstance(TmsDao.TMS_CHECK_CAR_INFO);
		dao.saveCheckcarInfo(EntityToDto(entity));
	}

	/**
	 * 获得查验车辆基本信息
	 * @param serial
	 * @return
	 * @throws TmsDaoException
	 */
	public CheckInfo getCheckInfo(String serial) throws TmsDaoException {
		CheckInfoDao dao = (CheckInfoDao) TmsDao
				.getInstance(TmsDao.TMS_CHECK_CAR_INFO);
		CheckInfoDto dto = dao.getCheckInfo(serial);
		CheckInfo entity = CheckInfo.getInstance();
		if(dto!=null){
			entity.setSerial(dto.getSerial());
			entity.setLicensePlate(dto.getLicensePlate());
			entity.setVin(dto.getVin());
			entity.setCarOwner(dto.getCarOwner());
			entity.setCardType(dto.getCardType());
			entity.setOwnerType(dto.getOwnerType());
			entity.setCarOwnerIdCardNo(dto.getCarOwnerIdCardNo());
			entity.setOwnerOrgNo(dto.getOwnerOrgNo());
			entity.setOwnerAddress(dto.getOwnerAddress());
			return entity;
		}
	
		return null;

	}

	/**
	 * Entity转换成DTO
	 * 
	 * @param entity
	 * @return
	 * @throws TmsDaoException
	 */
	private CheckInfoDto EntityToDto(CheckInfo entity) throws TmsDaoException {
		CheckInfoDto dto = new CheckInfoDto();
		// 流水号
		dto.setSerial(entity.getSerial());
		// 车牌号码
		dto.setLicensePlate(entity.getLicensePlate());
		// VIN码
		dto.setVin(entity.getVin());
		// 号牌种类
		dto.setCardType(entity.getCardType());
		// 车主类型
		dto.setOwnerType(entity.getOwnerType());
		// 车主姓名
		dto.setCarOwner(entity.getCarOwner());
		// 车主身份证号
		dto.setCarOwnerIdCardNo(entity.getCarOwnerIdCardNo());
		// 组织机构代码证号
		dto.setOwnerOrgNo(entity.getOwnerOrgNo());
		// 车主地址
		dto.setOwnerAddress(entity.getOwnerAddress());
		// 受理人
		dto.setInsertUserId(entity.getInsertUserId());
		// 更新人
		dto.setUpdateUserId(entity.getUpdateUserId());
		return dto;
	}

	/**
	 * 根据车辆ID查询查验信息是否存在信息是否存在
	 * 
	 * @return
	 * @throws TmsDaoException
	 */
	public boolean checkSerialExist(String serial) throws TmsDaoException {
		CheckInfoDao dao = (CheckInfoDao) TmsDao
				.getInstance(TmsDao.TMS_CHECK_CAR_INFO);

		boolean bsflag = dao.checkSerialExist(serial);

		return bsflag;
	}

	public String getId() {
		return id;
	}

	public void setId(String id) {
		this.id = id;
	}

	public String getSerial() {
		return serial;
	}

	public void setSerial(String serial) {
		this.serial = serial;
	}

	public String getLicensePlate() {
		return licensePlate;
	}

	public void setLicensePlate(String licensePlate) {
		this.licensePlate = licensePlate;
	}

	public String getVin() {
		return vin;
	}

	public void setVin(String vin) {
		this.vin = vin;
	}

	public int getCardType() {
		return cardType;
	}

	public void setCardType(int cardType) {
		this.cardType = cardType;
	}

	public int getOwnerType() {
		return ownerType;
	}

	public void setOwnerType(int ownerType) {
		this.ownerType = ownerType;
	}

	public String getCarOwner() {
		return carOwner;
	}

	public void setCarOwner(String carOwner) {
		this.carOwner = carOwner;
	}

	public String getCarOwnerIdCardNo() {
		return carOwnerIdCardNo;
	}

	public void setCarOwnerIdCardNo(String carOwnerIdCardNo) {
		this.carOwnerIdCardNo = carOwnerIdCardNo;
	}

	public String getOwnerOrgNo() {
		return ownerOrgNo;
	}

	public void setOwnerOrgNo(String ownerOrgNo) {
		this.ownerOrgNo = ownerOrgNo;
	}

	public String getOwnerAddress() {
		return ownerAddress;
	}

	public void setOwnerAddress(String ownerAddress) {
		this.ownerAddress = ownerAddress;
	}

	public int getInsertUserId() {
		return insertUserId;
	}

	public void setInsertUserId(int insertUserId) {
		this.insertUserId = insertUserId;
	}

	public Timestamp getInsertTime() {
		return insertTime;
	}

	public void setInsertTime(Timestamp insertTime) {
		this.insertTime = insertTime;
	}

	public int getUpdateUserId() {
		return updateUserId;
	}

	public void setUpdateUserId(int updateUserId) {
		this.updateUserId = updateUserId;
	}

	public Timestamp getUpdateTime() {
		return updateTime;
	}

	public void setUpdateTime(Timestamp updateTime) {
		this.updateTime = updateTime;
	}

	@Override
	public void save() throws TmsDaoException, TmsException {

	}

}
